﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using NazTek.Extension.Clr4;

namespace NazTek.Extension.Clr4.Test
{
    /// <summary>
    ///This is a test class for ArrayExtensionTest and is intended
    ///to contain all ArrayExtensionTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ArrayExtensionTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion
                
        /// <summary>
        ///A test for generic equals with a null target array
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(System.ArgumentNullException))]
        public void TestGenericEquals_NullArray()
        {
            string[] oArray1 = new string[] { "one", "two" };
            string[] oArray2 = null;
            oArray1.Equals<string>(oArray2);
        }
        /// <summary>
        ///A test for generic equals with a null target array.  Returns error message
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(System.ArgumentNullException))]
        public void TestGenericEquals_NullArrayWithMessage()
        {
            string[] oArray1 = new string[] { "one", "two" };
            string[] oArray2 = null;
            string failureMessage = null;
            try
            {
                oArray1.Equals<string>(oArray2, out failureMessage);
            }
            catch
            {
                Assert.IsNull(failureMessage);
                throw;
            }
        }
        /// <summary>
        ///A test for generic equals with different size arrays
        ///</summary>
        [TestMethod()]
        public void TestGenericEquals_VariableSize()
        {
            string[] oArray1 = new string[] { "one", "two" };
            string[] oArray2 = new string[] { "one", "two", "three" };
            Assert.IsFalse(oArray1.Equals<string>(oArray2));
        }
        /// <summary>
        ///A test for generic equals with different size arrays.  Returns error message.
        ///</summary>
        [TestMethod()]
        public void TestGenericEquals_VariableSizeWithMessage()
        {
            string[] oArray1 = new string[] { "one", "two" };
            string[] oArray2 = new string[] { "one", "two", "three" };
            string failureMessage = null;
            Assert.IsFalse(oArray1.Equals<string>(oArray2, out failureMessage));
            Assert.IsNotNull(failureMessage);
        }
        /// <summary>
        ///A test for generic equals with different string cased arrays
        ///</summary>
        [TestMethod()]
        public void TestGenericEquals_VariableContent()
        {
            string[] oArray1 = new string[] { "one", "two", "THREE" };
            string[] oArray2 = new string[] { "one", "two", "three" };
            Assert.IsFalse(oArray1.Equals<string>(oArray2));
        }
        /// <summary>
        ///A test for generic equals with different string cased arrays
        ///</summary>
        [TestMethod()]
        public void TestGenericEquals_VariableContentWithMessage()
        {
            string[] oArray1 = new string[] { "one", "two", "THREE" };
            string[] oArray2 = new string[] { "one", "two", "three" };
            string failureMessage = null;
            Assert.IsFalse(oArray1.Equals<string>(oArray2, out failureMessage));
            Assert.IsNotNull(failureMessage);
        }
        /// <summary>
        ///A test for generic equals with different string cased arrays
        ///</summary>
        [TestMethod()]
        public void TestGenericEquals()
        {
            string[] oArray1 = new string[] { "one", "two", "three" };
            string[] oArray2 = new string[] { "one", "two", "three" };
            Assert.IsTrue(oArray1.Equals<string>(oArray2));
        }
        /// <summary>
        ///A test for generic ToString
        ///</summary>
        [TestMethod()]
        public void TestToString()
        {
            string[] oStringArray = new string[] { "one", "two", "three" };
            Assert.AreEqual<string>("one,two,three", oStringArray.ToString<string>(","));
            int[] oIntArray = new int[] { 1, 2, 3 };
            Assert.AreEqual<string>("1,2,3", oIntArray.ToString<int>(","));
        }
        /// <summary>
        ///A test for generic ToString
        ///</summary>
        [TestMethod()]
        public void TestToString_Compact()
        {
            string[] oStringArray = new string[] { "one", "two", null, "", " ", "three" };
            Assert.AreEqual<string>("one,two,,,,three", oStringArray.ToString<string>(","));
            string[] oStringArray2 = new string[] { "one", "two", null, "", " ", "three" };
            Assert.AreEqual<string>("one|two|three", oStringArray2.ToString<string>("|", true));
            int[] oIntArray = new int[] { 1, 2, 3, 0 };
            Assert.AreEqual<string>("1|2|3|0", oIntArray.ToString<int>("|"));
        }
    }
}
